# Definition for a Node.
class Node:
    def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None):
        self.val = int(x)
        self.next = next
        self.random = random
head=Node(7,None,None)
head.next=Node(13)
head.next.next=Node(11)
head.next.next.next=Node(10)
head.next.next.next.next=Node(1)
head.random=None
head.next.random=head
head.next.next.random=head.next.next.next.next
head.next.next.next.random=head.next.next
head.next.next.next.next.random=head
def copyRandomList(head):
        #head链表的操作指针
        headPro=head
        list1=[]
        dictionary={None:None}
        while headPro:
            newNode=Node(headPro.val,None,headPro.random)
            list1.append(newNode)
            dictionary[headPro]=newNode
            headPro=headPro.next
        newHead=list1[0]
        newHeadPro=list1[0]
        for i in range(1,len(list1)):
            newHeadPro.next=list1[i]
            newHeadPro.random=dictionary[newHeadPro.random]
            newHeadPro=newHeadPro.next
        #对最后一个结点进行处理
        newHeadPro.random=dictionary[newHeadPro.random]
        while newHead:
            print("newHead:",newHead.val)
            if newHead.random:
                print("random:",newHead.random.val)
            else:
                print("random:",None)
            newHead=newHead.next
copyRandomList(head)




